package au.edu.swin.MelbourneMap;

import java.util.*;
import java.io.*;

// Download commons-lang3-3.1.jar
// from http://commons.apache.org/lang/
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.CompareToBuilder;

/**
 * Data structure to define a node. 
 *
 * @author  Alexis Wellavize (s/n: 6033482)<br/>
 *           Dotan Tamir (s/n: 6532969)
 * @since   v1, created:  13/10/2012
 * @version v2, modified:  13/10/2012
 *
 */
 
public final class Node
    //implements Comparable<Node>
{

    /// Easting and Northing coordinates
    private Double easting, northing;

    // Overloaded constructor
    public Node( Double easting, Double northing )
    {
        this.easting = easting;
        this.northing = northing;
    }
    
    // Accessor methods
    
    /**
     * Returns easting coordinate of node.
     * @return Easting coordinate of node.
     */    
    public Double getEasting()
    {
        return easting;
    }
    
    /**
     * Returns northing coordinate of node.
     * @return Northing coordinate of node.
     */    
    public Double getNorthing()
    {
        return northing;
    }

    // Mutator methods
    
    /**
     * Sets the northing coordinate of this node.
     * @param northing - The northing coordinate of this node.
     */
    public void setNorthing( Double northing )
    {
    	this.northing = northing;
    } 

    /**
     * Sets the easting coordinate of this node.
     * @param easting - The easting coordinate of this node.
     */    
    public void setEasting( Double easting )
    {
    	this.easting = easting;
    }

    public int compareTo( Object obj )
    {
        Node rhs = (Node) obj;
        return new CompareToBuilder()
            //.appendSuper( super.compareTo( obj ) )
            .append( this.easting, rhs.easting )
            .append( this.northing, rhs.northing )
            .toComparison();
    }
    
    @Override
    public boolean equals( Object obj )
    { 
        if ( obj == null ) 
            return false; 
        if ( obj == this ) 
            return true; 
        if ( obj.getClass() != getClass() ) 
            return false;
 
        Node rhs = (Node) obj; 
        return new EqualsBuilder() 
            //.appendSuper( super.equals( obj ) ) 
            .append( this.easting, rhs.easting )
            .append( this.northing, rhs.northing )
            .isEquals(); 
    } 

    @Override
    public int hashCode()
    { 
        return new HashCodeBuilder(17, 31)  // two random prime numbers 
            //.appendSuper( super.hashCode() )
            .append( this.easting )
            .append( this.northing )
            .toHashCode(); 
    } 
}